package com.szp.lagou.dubbo.filerDemo.provider.service;

import com.szp.lagou.dubbo.filerDemo.filter.TransportIPFilter;
import com.szp.lagou.dubbo.filerDemo.provider.service.HelloService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service
public class HelloServiceImpl implements HelloService {
    Logger logger = LoggerFactory.getLogger(HelloServiceImpl.class);
    @Override
    public String sayHello(String word) {
        RpcContext rpcContext = RpcContext.getContext();
        String clientIp = rpcContext.getAttachment(TransportIPFilter.CLIENT_IP_KEY);
        logger.info("从RpcContext中获取到客户端ip为:" + clientIp);
        System.out.println("从RpcContext中获取到客户端ip为:" + clientIp);
        return "Provider1 " + clientIp + " say hello " +word;
    }
}
